package org.six11.ss.client.olive;

import java.awt.Graphics2D;
import java.util.ConcurrentModificationException;
import java.util.List;

import org.six11.util.pen.Sequence;

/**
 * This is the parent class for rendering Sequence objects.
 * 
 * @author Gabe Johnson <johnsogg@cmu.edu>
 * 
 */
public abstract class SequenceRenderer {

  public final void renderSequences(Graphics2D g, List<Sequence> manySequences) {
    boolean tryAgain = true;
    while (tryAgain) {
      try {
        for (Sequence seq : manySequences) {
          render(g, seq);
        }
        tryAgain = false;
      } catch (ConcurrentModificationException ex) {
        // It is possible that the download thread will put more data in here during a render. In
        // that case, the iterator's 'getNext' will cause a concurrency error. That is OK though,
        // since the rendering will always update fairly soon after. We'll just try again until no
        // error happens.
      }
    }
  }

  public abstract void render(Graphics2D g, Sequence seq);

}
